package cn.tedu.feign.controller;

import cn.tedu.feign.feign.ItemFeign;
import cn.tedu.feign.feign.OrderFeign;
import cn.tedu.feign.feign.UserFeign;
import com.ljz.pojo.Item;
import com.ljz.pojo.Order;
import com.ljz.pojo.User;
import com.ljz.web.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by LJZ.
 * User: UID
 * Date:2020/6/19
 * Time: 17:16
 * To change this template use File | Settings | File Templates.
 */
@Slf4j
@RestController
public class FeignController {
    @Autowired
    private ItemFeign itemFeign;
    @Autowired
    private OrderFeign orderFeign;
    @Autowired
    private UserFeign userFeign;

    //item-service
    @GetMapping("/item-service/{orderId}")
    public JsonResult<List<Item>> getItems(@PathVariable String orderId) {
        return itemFeign.getItems(orderId);
    }

    @PostMapping("/item-service")
    public JsonResult decreaseNumber(@RequestBody List<Item> items) {
        return itemFeign.decreaseNumber(items);
    }

    //user-service
    @GetMapping("/user-service/{userId}")
    public JsonResult<User> getUser(@PathVariable Integer userId) {
        return userFeign.getUser(userId);
    }

    @GetMapping("/user-service/{userId}/score")
    public JsonResult addScore(@PathVariable Integer userId, @RequestParam Integer score) {
        return userFeign.addScore(userId, score);
    }

    //order-service
    @GetMapping("/order-service/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId) {
        return orderFeign.getOrder(orderId);
    }

    @GetMapping("/order-service")
    public JsonResult addOrder() {
        return orderFeign.addOrder();
    }
}
